package controllers;

import play.*;
import play.cache.Cache;
import play.libs.F;
import play.libs.WS;
import play.libs.WS.HttpResponse;
import play.mvc.*;
import play.mvc.results.RenderHtml;

import java.util.*;

import common.ArticleReader;
import common.DateUtils;
import common.cache.CacheManager;
import common.cache.CacheMode;
import common.rssReader.Rss;
import common.rssReader.RssItem;
import common.rssReader.RssReader;

import models.*;


public class Application extends Controller {
    
	
	public static void index() {
		render();
	}

	public static void news(long Id) {
		Article article = Article.getArticle(CacheMode.CentralPartionCache, Id);
		List<Tag> tags =  null;
		if(article != null){
			tags = article.getTags(CacheMode.CentralPartionCache);
		}
		render(article,tags);
	}

	public static void newsAll(String mail) {
		
		User user = new User(mail);
		user.save();
		
		String cacheMode = params.get("cacheMode");
		if(cacheMode != null){
		   System.out.println("cahcheMode:"+cacheMode);
		}
		int  nextOffSet = 0;
		  if(params.get("next") != null){
			 nextOffSet = Integer.valueOf(params.get("next"));	  
	        		 
		  } 
		
		List<Article> articleList = (List<Article>) CacheManager.getJavaCacheItem("lastArticle");
		
		if(articleList == null)
			articleList = Article.getArticleOrderByDate(CacheMode.CentralPartionCache,nextOffSet);
	
		render(user,articleList);
	}
}